package controllers;

import com.google.gson.JsonObject;

import models.IdeaDeveloper;
import play.mvc.Controller;
import play.mvc.With;

/**
 * @author KimO
 */
public class ForgetPassword extends Controller {
	/**
	 * renders the page of forget password
	 * 
	 * @author KimO
	 */
	public static void ForgetPassword() {
		render();
	}

	/**
	 * Sends the password of a given user after having his email and checking
	 * for him in the database
	 * 
	 * @author KimO
	 * 
	 * @param eMail
	 *            the email of the user who forgot his password
	 */
	public static void passwordSending(String eMail) {
		try {
			IdeaDeveloper ideaDev = (IdeaDeveloper) IdeaDeveloper
					.find("eMail = ?", eMail).fetch().get(0);
			IdeaDeveloper.sendEMail(eMail, "Password .. MEGASOFT application",
					"Your password is : " + ideaDev.password + " \nYa mastool");
			JsonObject json = new JsonObject();
			json.addProperty("res", "done");
			renderJSON(json.toString());
		} catch (Exception e) {
			JsonObject json = new JsonObject();
			json.addProperty("res", "Wrong Email!");
			renderJSON(json.toString());
		}
	}
}
